<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content" style="height: 100px">
        <form class="form-horizontal m" id="form-teachPersonalDocuments-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">文件名：</label>
				<div class="col-sm-8">
					<input id="filePath" name="filePath" class="form-control" type="file">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<label class="col-sm-3 control-label">上传人：</label>
					<div class="col-sm-8">
						<!--<input id="subjectId" name="subjectId" class="form-control" type="text">-->
						<select id="createBy" name="createBy" class="form-control" type="text"></select>
					</div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "teach/teachPersonalDocuments"
		$(function() {
			subjectSelect()
		})

		function submitHandler() {
			if ($.validate.form()) {
				uploadFile();
			}
		}

		function subjectSelect() {
			//进入班级选择且classId有值时查询当前项目值存入下拉框
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/user/list",
				// data : {"classId" : classId},
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					var subject = data.rows;
					addOptions(subject);
				}
			});
		}

		function addOptions(subject) {
			var pro = $('select[name="createBy"]');
			pro.children().remove();

			var options = "";
			$(subject).each(function() {
				options += '<option value="' + this.loginName + '" >' + this.userName + '</option>';
			});

			pro.append(options);
		}

		function uploadFile() {
			var formData = new FormData();
			if ($('#filePath')[0].files[0] == null) {
				$.modal.alertWarning("请先选择文件路径");
				return false;
			}
			formData.append('file', $('#filePath')[0].files[0]);
			formData.append('remark',$("#remark").val());
			formData.append('createBy',$("#createBy").val());
			$.ajax({
				url: prefix + "/add",
				type: 'post',
				cache: false,
				data: formData,
				processData: false,
				contentType: false,
				dataType: "json",
				success: function(result) {
					$.operate.successCallback(result);
				}
			});
		}
	</script>
</body>
</html>
